package com.example.androidhive;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import java.util.Map;

public class File_ extends _base_{
    public File_() {}
    
    public boolean openFile(int value) {
                    File f = new File(PathToFile(value));
                    return f.exists();
    }

    void saveToFile(int value) {
            try {
                    FileOutputStream fout = null;
                    fout = new FileOutputStream(PathToFile(value));
                    ObjectOutputStream oos = new ObjectOutputStream(fout);
                    oos.writeObject(aaa);
                    oos.close();
            } catch (Exception ex) {
                    ex.printStackTrace();
            }
    }

    /**
     * 
     * @param a
     * @param b
     * @param value
     *            (0-commands,1-labs)
     */
    public void addToMap(String a, String b, int value) {
            if (openFile(value)) {
                    readFile(value);
            }
           // aaa.put(a+b, b);
           // address.setMapa(mapa_);
            saveToFile(value);
    }
    /**
     * 
     * @param a
     * @param b
     * @param value
     *            (0-lotto,1-labs)
     */
    public void addToMap2(String a,List<String> b, int value) {
            if (openFile(value)) {
                    readFile(value);
            }
            aaa.put(a, b);
           // address.setMapa(mapa_);
            saveToFile(value);
    }

   /* public Map<String, String> getValues() {
            return address.getMapa();
    }*/
    public Map<String,List<String>> readF(int value){
            readFile(value);
            return aaa;
    }
    

     void readFile(int value) {
            try {
                    if(openFile(value)){
                    FileInputStream fin = null;
                    fin = new FileInputStream(PathToFile(value));
                    ObjectInputStream ois = new ObjectInputStream(fin);
                    //mapa_address = (_FILE_) ois.readObject();
                    aaa=(Map<String,List<String>>)ois.readObject();
                    ois.close();
                   // mapa_=aa;
                    //mapa_ = address.getMapa();
                    }
            } catch (Exception ex) {
                    ex.printStackTrace();
            }
    }
    @Override
    void method1() {
            // TODO Auto-generated method stub
            
    }
}
